<?php
class titleGenerator {
    function getTitle($pageid, $page, $apage, $epage, $article) {
        $connect = new mysqli(DB_HOST,DB_USER,DB_PASS,DB_NAME);
        if($result = $connect->query("SELECT title, category FROM ".$prefix."posts WHERE id = '".$article."'")) {
            $row = $result->fetch_object();
            $countUser = $connect->query("SELECT username FROM ".$prefix."users");
            $userCount = $countUser->num_rows;
            $countPosts = $connect->query("SELECT id FROM ".$prefix."posts WHERE time > NOW() - INTERVAL 1 YEAR AND draft = '0'");
            $postCount = $countPosts->num_rows;

            $titleShifter = array(
                "$userCount registered users",
                "$postCount news articles this year"
            );
            $randomtitle = array_rand($titleShifter);

            switch($pageid) {
                default;
                    $this->title = ucfirst($page);
                    break;
                case "1"; //home
                case "";
                    $this->title = 'Softsaurus.org '.$titleShifter[$randomtitle];
                    break;
                case "2"; //news
                    switch($article) {
                        default;
                            $this->title = $row->title.' | '.$row->category;
                            break;
                        case "";
                            $this->title = "Latest 10 posts";
                            break;
                    }
                    break;
                case "8"; //admin
                    $this->title = ucfirst($page).' | '.ucfirst($apage);
                    break;
            }

            return $this->title;
            $result->close();
        } else {
            return $connect->error;
        }
        $connect->close();
    }
}
?>
